package cn.ljy.uem.web.action.frontend.mobile.course;

import cn.ljy.authority.config.security.TokenUtil;
import cn.ljy.authority.model.SysUser;
import cn.ljy.authority.service.SysUserTokenFrontendService;
import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.annotation.LimitRequest;
import cn.ljy.common.model.result.ResponseData;
import cn.ljy.uem.model.SchoolCourseSectionResourceComment;
import cn.ljy.uem.model.SchoolStudent;
import cn.ljy.uem.model.query.SchoolCourseSectionResourceCommentQuery;
import cn.ljy.uem.service.SchoolCourseSectionResourceCommentService;
import cn.ljy.uem.service.SchoolStudentService;
import cn.ljy.uem.service.common.CommonSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;


/**
 * 教学章节资源评论控制器
 * @author 王秋林
 * @date 2022/09/15
 */
@Api(tags = "移动端的教学章节资源评论模块")
@RestController
@RequestMapping(value = "/api/mobile/schoolstudent/schoolCourseSectionResourceComment")
public class SchoolCourseSectionResourceCommentMobileController extends BaseBackstageController<SchoolCourseSectionResourceComment, SchoolCourseSectionResourceCommentQuery, String> {

    @Autowired
    private SysUserTokenFrontendService sysUserTokenFrontendService;
    @Autowired
    private CommonSchoolService commonSchoolService;
    @Autowired
    private SchoolCourseSectionResourceCommentService service;

    @Autowired
    private SchoolStudentService schoolStudentService;

    @ApiOperation(value = "课程章节资源评论")
    @GetMapping("/all")
    @Override
    protected ResponseData query(SchoolCourseSectionResourceCommentQuery query) {
        return super.query(query);
    }


    @ApiOperation(value = "读取课程章节资源评论信息")
    @Override
    protected ResponseData get(@PathVariable("id") String id) {
        return super.get(id);
    }

    @ApiOperation(value = "批量删除指定的多个课程章节资源评论")
    @Override
    protected ResponseData deletes(@NotEmpty(message = "操作失败：请选择要移除的记录") String[] ids) {
        return super.deletes(ids);
    }


    @ApiOperation(value = "添加课程章节资源评论")
//    @LimitRequest
//    @PostMapping(value = "/save")
    @Override
    protected ResponseData add(@Valid @RequestBody SchoolCourseSectionResourceComment schoolCourseSectionResourceComment) {
        String token= TokenUtil.getAppToken();//读取前台token的值
        //获取登录账户信息
        SysUser user=sysUserTokenFrontendService.getUserFromToken(token);
        //获取登录账户对应的学生信息
        schoolCourseSectionResourceComment.setSysUser(user);
        schoolCourseSectionResourceComment.setUserId(user.getId());
//        SchoolStudent student=commonSchoolService.getStudent(user);
        service.save(schoolCourseSectionResourceComment);
        return ResponseData.success(null);
    }

    @ApiOperation(value = "编辑课程章节资源评论")
    @Override
    protected ResponseData edit(@Valid @RequestBody SchoolCourseSectionResourceComment schoolCourseSectionResourceComment) {
        return super.edit(schoolCourseSectionResourceComment);
    }


}
